﻿using System;
using System.Web;

namespace Azure.Online.Proxy.Server {
    public class QueryDictionary : NameValueDictionary {

        public QueryDictionary() {

        }

        public QueryDictionary(Uri uri) {
            var query = uri.Query;
            if (!string.IsNullOrWhiteSpace(query)) {
                if (query.Length > 0 && query[0] == '?') {
                    query = query.Substring(1);
                }
                var parts = query.Split('&');
                foreach (var part in parts) {
                    var args = part.Split('=');
                    var name = args[0];
                    var value = args.Length > 1 ? args[1] : "";

                    name = HttpUtility.UrlDecode(name);
                    value = HttpUtility.UrlDecode(value);
                    this[name] = value;
                }
            }
        }
    }
}
